package com.neuedu.io;

import java.io.*;

public class DataStreamDemo {
    public static void main(String[] args) {
        File  file = new File("d://123.txt");
        if(!file.exists()){
            try {
                file.createNewFile();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        try {
            DataOutputStream  dos = new DataOutputStream(new FileOutputStream(file));
            DataInputStream   dis = new DataInputStream(new FileInputStream(file));

            dos.writeDouble(3.14);
            dos.writeBoolean(true);
            dos.writeInt(100);
            dos.writeLong(9113456789012345678L);

            double   d = dis.readDouble();
            boolean   b = dis.readBoolean();
            int i = dis.readInt();
            long  l = dis.readLong();

            System.out.println("boolean:"+b);
            System.out.println("double:"+d);
            System.out.println("long:"+l);
            System.out.println("int:"+i);

            dos.close();
            dis.close();


        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
